Repository navigation
Conversation
Pagefind's browser runtime defaults to /pagefind/ and is often cached longer than the index files. After an upgrade, returning visitors can load an old runtime against a new index and search fails with a version mismatch. Move the generated bundle to /pagefind-<installed version>/ and point both the script import and the Pagefind basePath at it, so a version change always yields a new URL. Add a build check that asserts generated pages reference the versioned bundle.
|
@Henglie is attempting to deploy a commit to the zephyirdgmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Checklist
Related Issue
Fixes #774
Changes
Pagefind's browser runtime is loaded from the unversioned
/pagefind/pagefind.jsand defaults to/pagefind/as its base path. Hosting providers commonly cache that file far longer than the generated index, so after a Pagefind upgrade a returning visitor can load the old runtime against the new index. Search then fails withPagefind JS version doesn't match the version the index was built withand no visible response.dist/pagefind-<installed version>/afterpagefind --site distruns (scripts/version-pagefind.mjs).astro.config.mjsand expose it as__PAGEFIND_VERSION__.Navbar.astro, import the runtime from the versioned path and pass the same path asbasePath, so the runtime and index always come from the same version.pnpm check:pagefind(scripts/check-pagefind-versioned.mjs) to assert that every generated page references the versioned runtime and base path and that the legacydist/pagefinddirectory is gone.Example output with Pagefind 1.4.0:
dist/pagefind-1.4.0/pagefind.js,const scriptUrl = "/pagefind-1.4.0/pagefind.js";,const basePath = "/pagefind-1.4.0/";.How To Test
pnpm install --frozen-lockfilepnpm build-> Astro 5.13.10 build succeeds, Pagefind 1.4.0 indexes 6 pages, bundle is moved todist/pagefind-1.4.0.pnpm check:pagefind->OK: 8 page(s) reference Pagefind 1.4.0 under /pagefind-1.4.0/.dist/pagefind-1.4.0/from a local HTTP server, importedpagefind.js, setbasePathto the versioned directory, and ransearch("markdown"); it returned 4 results (/posts/markdown-extended/,/posts/markdown/,/posts/video/).pnpm buildregeneratesdist/pagefind/pagefind.js, andnode scripts/check-pagefind-versioned.mjsexits 1 reporting the legacy path and missing versioned assets.Not verified in this PR:
pnpm astro checkreports 2 errors andpnpm type-checkreportsisolatedDeclarationserrors in untouched files; both sets reproduce on unmodifiedmainand are unrelated to this change.